package com.tanhua.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.manage.domain.AdminLog;
import com.tanhua.manage.mapper.AdminLogMapper;
import com.tanhua.manage.service.IAdminLogService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class AdminLogServiceImpl implements IAdminLogService {

    @Autowired
    private AdminLogMapper adminLogMapper;

    @Override
    public void saveLog(AdminLog adminLog) {
        adminLogMapper.insert(adminLog);
    }

    @Override
    public Page<AdminLog> queryAll(Integer curPage, Integer pageSize,  String created, String operModul,String userName) {
        Page<AdminLog> page=new Page<>(curPage,pageSize);
        QueryWrapper<AdminLog> queryWrapper=new QueryWrapper<>();

        if (!StringUtils.isEmpty(userName)){
            queryWrapper.like("oper_user_name",userName);
        }
        if (!StringUtils.isEmpty(created)){
            queryWrapper.ge("created",created);
            queryWrapper.orderByAsc("created");
        }else {
            queryWrapper.orderByDesc("created");
        }
        if (!StringUtils.isEmpty(operModul)){
            queryWrapper.eq("oper_modul",operModul);
        }

        Page<AdminLog> adminLogPage = adminLogMapper.selectPage(page, queryWrapper);

        return adminLogPage;
    }


}
